from scripts.init_price_police import S28
from django import forms
from web.views.account import BootstragForm
from scripts.init_price_police import S28
from django.core.exceptions import ValidationError
from web.forms.my_color_widget import ClolrRadioSelect


class WikiForm(BootstragForm, forms.Form):

    def __init__(self, requested, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.requested = requested
        li = [('null', 'null')]
        ret = S28().py_searche('select * from wiki where father_id is null and project_id="{}"'.format(self.requested))


        for i in ret:
            li.append((i[0], i[1]))
        self.fields['father_id'].choices = li




    title = forms.CharField(max_length=60, label='标题')
    content = forms.CharField(widget=forms.Textarea(attrs={'style': 'resize: none'}), max_length=62000, label='内容')
    father_id = forms.ChoiceField(choices=(('xx', 'xx')), label='设置父级')

class Wiki_editForm(BootstragForm, forms.Form):

    def __init__(self, requested, wike_tuple, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.requested = requested
        self.wike_tuple = wike_tuple

        li = [('null', 'null')]
        ret = S28().py_searche('select * from wiki where father_id is null and project_id="{}"'.format(self.requested))
        for i in ret:
            li.append((i[0], i[1]))
        self.fields['father_id'].choices = li
        self.fields['title'].widget.attrs = {'value': self.wike_tuple[1], 'class': 'form-control'}
        # self.fields['content'].widget.attrs = {'value': '前面的朋友你们好吗？', 'class': 'form-control', 'style': 'resize: none'}


    title = forms.CharField(max_length=60, label='标题')
    content = forms.CharField(widget=forms.Textarea(attrs={'style': 'resize: none'}), max_length=62000, label='内容')
    father_id = forms.ChoiceField(choices=(('xx', 'xx')), label='设置父级')
